﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using _3Dsoundor2Dgraphor.Sound;

namespace _3Dsoundor2Dgraphor.Graphics
{
	class Object : Element
	{
		private float radius;
		private PointF orbitCenter;
		private bool playing = false;

		private float size;
		private int speed;

		public bool moveable = false;

		public SoundSource sound; 

		public Object(int X, int Y, Color color, float _size)
		{
			_position.X = X;
			_position.Y = Y;
			mBrush = new SolidBrush(color);
			size = _size;
			radius = 5*size;
		}

		public Object(int X, int Y, Color color, float _size, bool _moveable, int pX, int pY, int _speed, int rad)
		{
			_position.X = X;
			_position.Y = Y;
			mBrush = new SolidBrush(color);
			size = _size;
			radius = rad;
			orbitCenter.X = pX;
			orbitCenter.Y = pY;
			speed = _speed;
			moveable = _moveable;
		}


		public void createSound (string path, bool loop)
		{
			sound = new SoundSource(path, loop, _position);
		}

		public override void draw(System.Drawing.Graphics output)
		{
			if(moveable)
			{
				_position.X = orbitCenter.X + sceneX + (float)Math.Sin((double)(time * speed) / 50) * radius;
				_position.Y = orbitCenter.Y + sceneY + (float)Math.Cos((double)(time * speed) / 50) * radius;

			}
			output.DrawEllipse(new Pen(mBrush), _position.X, _position.Y, size, size);
			sound.changePosition(_position);
		}

		public override void action(PointF point)
		{
			if (distance(_position, point) < radius)
			{
				if (SoundBase.system != null)
					sound.play(true);
			}
		}
		public override void stopAction(PointF point)
		{
			if (distance(_position, point) < radius)
			{
				if (SoundBase.system != null)
					sound.pause();
			}
		}

	}
}
